package com.wsgalaxy.anmanager;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.TextView;

import org.w3c.dom.Text;

/**
 * Created by wssxk on 9/23/17.
 */

public class MainActivity extends Activity {

    TextView log_show;
    MACallback ma_callback;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        log_show = (TextView) findViewById(R.id.textview_mainactivity_mesg);
        //log_show.setText("starting...\n");
        ma_callback = new MACallback();
        startService(new Intent(this, MainService.class));

        bindService(new Intent(MainActivity.this, MainService.class),
                new ServiceConnection() {
                    @Override
                    public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
                        ((MainService.MSBinder) iBinder).setCallback(ma_callback);
                        //((MainService.MSBinder) iBinder).test();
                    }

                    @Override
                    public void onServiceDisconnected(ComponentName componentName) {

                    }
                },
                Context.BIND_AUTO_CREATE);

        ma_callback.setText("starting...\n");
        //ma_callback.showInfo();

    }

    public class MACallback {
        String show_text = "";
        public void setText(String text) {
            Log.d("wssxk", "setText: " + text);
            show_text = "";
            show_text += text;
            log_show.setText(show_text);
        }

        public void addText(String text) {
            Log.d("wssxk", "addText: " + text);
            //show_text = "";
            show_text = text + "\n" + show_text;
            log_show.setText(show_text);
        }

        public void showInfo() {
            addText("board: " + Build.BOARD);                   //主板
            addText("brand: " + Build.BRAND);                   //系统定制商
            addText("device: " + Build.DEVICE);                 //工厂设备型号
            addText("manufacturer: " + Build.MANUFACTURER);     //硬件制造商
            addText("model: " + Build.MODEL);                   //用户设备型号
            addText("product: " + Build.PRODUCT);               //产品型号
            addText("SDK: " + Build.VERSION.SDK_INT);
            addText("release: " + Build.VERSION.RELEASE);
            addText("cpu_abi: " + Build.CPU_ABI);
            addText("property: " + System.getProperty("os.arch"));

        }

    }
}
